<?php

declare(strict_types=1);

namespace app\api\controller;

use think\facade\Request;
use think\facade\Db;
use app\api\controller\WxpayService;
use app\api\controller\Withdrawal;


class MealPass
{
    /**
     * @Action
     * 员工选择图标
     * @return void
     */
    public function setIcon($id,$cid,$uid,$openid){
        $onebmeal = Db::name('icon_details')->where('status',1)->where('is_deleted',0)->where('id',$id)->value('onebmeal');

        $cid = explode(',',$cid);
        if (in_array($id,$cid))
        {
            $onebmeal = $onebmeal.','. $uid;
        }else{
            $onebmeal = explode(',',$onebmeal);
            unset($onebmeal[array_search($uid,$onebmeal)]);
            $onebmeal = implode(',',$onebmeal);
        }

        $data = Db::name('icon_details')->where('status',1)->where('is_deleted',0)->where('id',$id)->update(['onebmeal'=>$onebmeal]);

        return $data;
    }



    /**
     * 数组去重
     * @Action
     * @return void
     */
    public function a_array_unique($array)
    {
        $out = array();
        foreach ($array as $key=>$value) {
            if (!in_array($value, $out))
            {
                $out[$key] = $value;
            }
        }
        return $out;
    }


}